package com.jie.template.impl;

import com.jie.po.EmailCodePO;
import com.jie.template.PlatformEmailManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;

/**
 * 抽象模板类
 * @Author: 杰
 * @Project :net-disk
 * @DateTime: 2024/4/29 10:29
 **/
@Slf4j
@Service("abstractEmailManage")
public abstract class AbstractEmailManage implements PlatformEmailManager {
    /**
     * 邮箱号
     */
    @Value("${spring.mail.username}")
    private String email;
    /**
     * 发送邮箱
     */
    public final void sendEmail(String from){
        log.info("发送邮箱");
        EmailCodePO simpleMailMessage=new EmailCodePO();
        generateEmailSenderAndReceiver(simpleMailMessage,from);
        generateEmailHeader(simpleMailMessage);
        //根据发送类型不同调用不同的实现类方法 //发送邮箱 自定义邮箱内
        this.generateEmailContent(simpleMailMessage);
    }

    /**
     * 谁发给谁
     * @param
     * @param from
     */
    @Override
    public void generateEmailSenderAndReceiver(EmailCodePO emailCodePO,String from) {
        emailCodePO.setFrom(email);
        emailCodePO.setTo(from);
    }
    /**
     * 设置头部信息
     * @param
     */

    @Override
    public void generateEmailHeader(EmailCodePO emailCodePO) {
        emailCodePO.setSubject("小杰健身App");
    }

    /**
     * 设置发送内容
     *1.生成验证码
     *2.发送邮箱
     *3. 并且redis存储一份验证码来进行验证
     * @param emailCodePO
     */
    public abstract void generateEmailContent(EmailCodePO emailCodePO);

}
